package interview;

public class interview_05_04 {
    public int[] findClosedNumbers(int num) {
        int count=number(num);
        if(count==31){
            return new int[]{-1,-1};
        }
        int[] result=new int[2];
        for(int i=num+1;i<=Integer.MAX_VALUE;++i){
            if(number(i)==count) {
                result[0]=i;
                break;
            }
        }
        if(result[0]==0) result[0]=-1;
        result[1]=Integer.MAX_VALUE;
        for(int i=num-1;i>0;--i){
            if(number(i)==count) {
                result[1]=i;
                break;
            }
        }
        if(result[1]==Integer.MAX_VALUE) result[1]=-1;
        return result;
    }
    public int number(int num){
        int count=0;
        while(num!=0){
            count+=num&1;
            num=num>>>1;
        }
        return count;
    }
}
